package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.system.domain.EmployeeBasicInfo;
import com.ruoyi.system.mapper.EducationTrainingMapper;
import com.ruoyi.system.domain.EducationTraining;
import com.ruoyi.system.service.IEducationTrainingService;

/**
 * 学习培训经历Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-22
 */
@Service
public class EducationTrainingServiceImpl implements IEducationTrainingService 
{
    @Autowired
    private EducationTrainingMapper educationTrainingMapper;

    /**
     * 查询学习培训经历
     * 
     * @param id 学习培训经历主键
     * @return 学习培训经历
     */
    @Override
    public EducationTraining selectEducationTrainingById(String id)
    {
        return educationTrainingMapper.selectEducationTrainingById(id);
    }

    /**
     * 查询学习培训经历列表
     * 
     * @param educationTraining 学习培训经历
     * @return 学习培训经历
     */
    @Override
    public List<EducationTraining> selectEducationTrainingList(EducationTraining educationTraining)
    {
        return educationTrainingMapper.selectEducationTrainingList(educationTraining);
    }

    /**
     * 新增学习培训经历
     * 
     * @param educationTraining 学习培训经历
     * @return 结果
     */
    @Transactional
    @Override
    public int insertEducationTraining(EducationTraining educationTraining)
    {
        int rows = educationTrainingMapper.insertEducationTraining(educationTraining);
        insertEmployeeBasicInfo(educationTraining);
        return rows;
    }

    /**
     * 修改学习培训经历
     * 
     * @param educationTraining 学习培训经历
     * @return 结果
     */
    @Transactional
    @Override
    public int updateEducationTraining(EducationTraining educationTraining)
    {
        educationTrainingMapper.deleteEmployeeBasicInfoByEmployeeId(educationTraining.getId());
        insertEmployeeBasicInfo(educationTraining);
        return educationTrainingMapper.updateEducationTraining(educationTraining);
    }

    /**
     * 批量删除学习培训经历
     * 
     * @param ids 需要删除的学习培训经历主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEducationTrainingByIds(String[] ids)
    {
        educationTrainingMapper.deleteEmployeeBasicInfoByEmployeeIds(ids);
        return educationTrainingMapper.deleteEducationTrainingByIds(ids);
    }

    /**
     * 删除学习培训经历信息
     * 
     * @param id 学习培训经历主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEducationTrainingById(String id)
    {
        educationTrainingMapper.deleteEmployeeBasicInfoByEmployeeId(id);
        return educationTrainingMapper.deleteEducationTrainingById(id);
    }

    /**
     * 新增员工基本信息信息
     * 
     * @param educationTraining 学习培训经历对象
     */
    public void insertEmployeeBasicInfo(EducationTraining educationTraining)
    {
        List<EmployeeBasicInfo> employeeBasicInfoList = educationTraining.getEmployeeBasicInfoList();
        String id = educationTraining.getId();
        if (StringUtils.isNotNull(employeeBasicInfoList))
        {
            List<EmployeeBasicInfo> list = new ArrayList<EmployeeBasicInfo>();
            for (EmployeeBasicInfo employeeBasicInfo : employeeBasicInfoList)
            {
                employeeBasicInfo.setEmployeeId(id);
                list.add(employeeBasicInfo);
            }
            if (list.size() > 0)
            {
                educationTrainingMapper.batchEmployeeBasicInfo(list);
            }
        }
    }
}
